Use EMODE
Go
select
	  cal.YEAR as YR
	, cal.QUARTER as QTR
	, cal.MONTH as MTH
	, cal.MONTH_NAME as MONTH_NAME
	, ol.STATE as STATE
	, ol.SHOP_NAME as STORE_NAME
	, SUM(sh.MARGIN) as MARGIN
	, SUM(sh.AMOUNT_SOLD) as SALES_REVENUE
	, SUM(sh.QUANTITY_SOLD) as QUANTITY_SOLD
from
	OUTLET_LOOKUP as ol
		inner join SHOP_FACTS sh
			on ol.SHOP_CODE = sh.SHOP_CODE
		inner join CALENDAR_YEAR_LOOKUP as cal
			on sh.WEEK_KEY = cal.WEEK_KEY
where
	cal.YEAR in (@YearsList)
and 
	cal.MONTH in (@MonthsList)
and
	ol.STATE in (@StatesList)
group by
	  cal.YEAR
	, cal.QUARTER
	, cal.MONTH
	, cal.MONTH_NAME
	, ol.STATE
	, ol.SHOP_NAME
order by
	  cal.YEAR desc
	, cal.QUARTER desc
	, cal.MONTH desc
	, ol.STATE asc
	, ol.SHOP_NAME asc;
